package org.my.workflow.condition;

import java.util.List;
import java.util.Map;

import org.my.workflow.Condition;
import org.my.workflow.WorkflowContext;
import org.my.workflow.WorkflowException;
import org.my.workflow.element.ConditionElement;
import org.my.workflow.element.StepElement;

/**
 * @author <a href="mailto:yang_y@sysnet.com.cn">Young Yang</a>
 */
public class JoinCondition implements Condition {

    public boolean isAllowed(WorkflowContext wfContext, ConditionElement conditionElement) throws WorkflowException {

        // current step 为 join 分支的其中一个 step
        List<StepElement> currentStepElements = wfContext.getCurrentStepElement();

        // isLastStep
        Map<String, String> args = conditionElement.getArgs();
        boolean isLastStep = true;
        int containsCount = 0;
        for(StepElement stepElement : currentStepElements){
            String stepElementId = stepElement.getId();
            if(args.containsKey(stepElementId)){
                containsCount++;
            }
            if(containsCount > 1) {
                isLastStep = false;
                break;
            }
        }

        //如果不是最后一个 Step，那么就要检查Join的其它Step是否已经完成
        boolean allowed = true;

        for(Map.Entry<String, String> entry : args.entrySet()){
            String stepId = entry.getKey();
            String stepStatus = entry.getValue();
            
        }

        //TODO: remove Queued Step
        
        return false;
    }

    public static void main(String[] args) {

    }
}
